package hao.itheima;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/request")
public class RequestServlet extends HttpServlet {
    //1、重写doGet方法
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.获取请求方式
        String method = req.getMethod();
        //快捷键  输出的东西.soutv  可以快速生成下面的输出语句
        System.out.println("method = " + method);
        //2.获取请求路径
        //遇到不会的只是点,先自己去测试
        String URI = req.getRequestURI();
        StringBuffer URL = req.getRequestURL();
        System.out.println("URI = " + URI);
        System.out.println("URL = " + URL);
        //3.获取请求协议
        String scheme = req.getScheme();
        System.out.println("scheme = " + scheme);
        //4.获取请求头(host)
        String header = req.getHeader("Host");//相当于根据key获取value
        System.out.println("header = " + header);
        //5.获取请求参数
        String name = req.getParameter("name");
        System.out.println("name = " + name);

    }
}
